/*
 * 作者：姚俊
 * 功能：通过名称来查找所有的工程项目
 * 日期：2015-05-25
 */
package admin.action.fruits;

import java.io.UnsupportedEncodingException;
import java.util.List;

import admin.service.fruits.ProjectService;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Project;

public class ProjectNameAction {
	
	private List<Project> projects;
	private String name;
	private int flag;
	private int code;
	//当前页
	private int currentPage;
	//最后一页
	private int endPage;
	private int counts;

	public List<Project> getProjects() {
		return projects;
	}

	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}
	
	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public String execute()
	{
		
		
		//解决a标签的中文乱码问题
		if(this.getCode()==1)
		{
			try {
				this.setName(new String(this.getName().getBytes("iso-8859-1"),"utf-8"));
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
		int add=0;
		if(new ProjectService().getCountProjectByName(this.getName())%Constant.pageSize!=0)
		{
			add=1;
		}
		
				
		ActionContext.getContext().put("flag", 2);
		this.setFlag(2);
		ActionContext.getContext().put("name", this.getName());
		this.setEndPage(new ProjectService().getCountProjectByName(this.getName())/Constant.pageSize+add);
		this.setCounts(new ProjectService().getCountProjectByName(this.getName()));
		
		//通过名称来查找所有项目
		projects=new ProjectService().getSegregateProjectByName(this.getName(),
				(this.getCurrentPage()-1)*Constant.pageSize+1, Constant.pageSize);
		return "succ";
	}

}
